using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using StillVoiceCommon;
using System.Text;
using System.IO;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;

/// <summary>
/// Summary description for FundingApplication
/// </summary>

namespace TeamTime.Classes
{

    public class Office : StillVoiceCommon.DataTableRow
    {
        #region properties
        //public string SupplierCompanyName { get; set; }
        //public string FundingFor { get; set; }

        #endregion

        public Office()
        {
            this.initClass(TN5Y.Utilities.DBConnectionString, "Office");
        }
        public new void load(string id)
        {
            base.load(id);
            System.Data.SqlClient.SqlDataReader dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text, 
                "select * from ViewOffices where ID = " + id);
            if (dr.Read())
            {
                //SupplierCompanyName =dr["CompanyName"].ToString();
                //FundingFor = dr["FundingFor"].ToString();
            }
            dr.Close();
            dr = null;
        }

        internal Int32 getAConsultantID()
        {
            //At this stage, just get the first one
            Int32 ret = 0;
            string sql = "SELECT top 1 isnull(ConsultantID,0) FROM ViewStaffMembers where OfficeID = @OfficeID and ConsultantID is not null";

            ret= Convert.ToInt32(  SqlHelper.ExecuteScalar(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("OfficeID", Convert.ToInt32(this.KeyValue))));
            if (ret == 0)
            {
                throw new Exception("No consultant found for Office: " + this.Fields["Description"].ToString()); 
            }
            else
                return ret;
        }

 
    }


   
}
